import numpy as np
import matplotlib.pyplot as plt
import sklearn.linear_model as linear_model

np.random.seed(42)

y = [np.random.random() for i in range(500)]
size = len(y)
ns = np.random.normal(0,1,size)
x = [y[i]+ns[i] for i in range(size)]

model_y2x = linear_model.LinearRegression()
model_y2x.fit([[i] for i in x],y)
ys = model_y2x.predict([[i] for i in x])
print(model_y2x.coef_)
print(model_y2x.intercept_)
fig = plt.figure()
plt.plot(x,y,c='blue')
plt.plot(x,ys,c='red')
plt.savefig("y2x.jpg")
plt.show()